package com.ofek.eventos;

import java.util.ArrayList;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.ofek.applicationbase.forms.FormFragment;
import com.ofek.applicationbase.utils.Log;
import com.ofek.eventos.db.EventosDatabaseService;
import com.ofek.eventos.db.EventosDatabaseService.EventosDatabaseServiceBinder;
import com.ofek.eventos.db.datatypes.Type;

public abstract class EventosFormFragment extends FormFragment {
	private ArrayList<Type> types;
	private ServiceConnection service;
	@Override
	public void onCreate(final Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		getActivity().bindService(new Intent(getActivity(),EventosDatabaseService.class), service = new ServiceConnection() {

			@Override
			public void onServiceDisconnected(final ComponentName name) {

			}

			@Override
			public void onServiceConnected(final ComponentName name, final IBinder service) {
				final EventosDatabaseService.EventosDatabaseServiceBinder binder = (EventosDatabaseServiceBinder) service;
				types = binder.getEventosService().getTypes();
				initForm(true);
			}
		}, 0);
	}
	@Override
	public void onResume() {
		Log.d("onResume");
		super.onResume();
	}

	@Override
	public void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		getActivity().unbindService(service);
	}
	@Override
	public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
			final Bundle savedInstanceState) {
		return super.onCreateView(inflater, container, savedInstanceState);
	}


}
